/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.zumbits.avd.mysql;

import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author joselito
 */
public class UserSQL {

    public static final int ALL = 0;
    public static final int LOGIN = 0;
    public static final int SENHA = 1;
    //
    private ArrayList<String> login;
    private ArrayList<String> senha;
    private Query query;

    public UserSQL(Mysql mysql) {
        query = new Query(mysql.getConnection());
        login = new ArrayList<String>();
        senha = new ArrayList<String>();
    }

    public ArrayList select(String login, String senha) throws SQLException {
        String sql = "SELECT * FROM avd";

        if (login != null) {
            sql += " WHERE login=\"" + login + "\"";

            if (senha != null) {
                sql += " AND senha=\"" + senha + "\"";
            }
        }

        ArrayList result = new ArrayList();

        query.executeQuery(sql);

        while (query.next()) {
            this.login.add(query.getString("login"));
            this.senha.add(query.getString("senha"));
        }

        if (this.login.size() > 0 && this.senha.size() > 0) {
            result.add(LOGIN, this.login);
            result.add(SENHA, this.senha);
        }

        return result;
    }
//    public boolean insert(String nome, String endereco, String fone) {
//        return query.execute("INSERT INTO Cliente VALUES(" +
//                "NULL, " +
//                "\"" + nome + "\", " +
//                "\"" + endereco + "\", " +
//                "\"" + fone + "\")");
//    }
//
//    public boolean delete(int codigo) {
//        return query.execute("DELETE FROM Cliente WHERE codigo=" + codigo);
//    }
//
//    public boolean update(int codigo, String nome, String endereco, String fone) {
//        return query.execute("UPDATE Cliente SET " +
//                "nome=\"" + nome + "\", " +
//                "endereco=\"" + endereco + "\", " +
//                "fone=\"" + fone + "\" " +
//                "WHERE codigo=" + codigo);
//    }
//
//    public List join(Object o) {
//        String tabela = o.getClass().toString();
//        //...
//        throw new UnsupportedOperationException("Not supported yet.");
//    }
//
//    public void clear() {
//        codigo.clear();
//        nome.clear();
//        endereco.clear();
//        fone.clear();
//    }
}
